//
//  VKJiFenShopHeaderView.m
//  V-Learn
//
//  Created by liubo on 2019/1/9.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKJiFenShopHeaderView.h"

@interface VKJiFenShopHeaderView ()
@property (nonatomic, strong) NSString *jifenString;
@end
@implementation VKJiFenShopHeaderView
/// 用这个
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        /// 设置布局
        [self setUpUI];
    }
    return self;
}

- (void)setUpUI{
    UIView *bgView = [[UIView alloc]init];
    [self addSubview:bgView];
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self);
        make.height.equalTo(@72);
        make.width.equalTo(@([UIScreen cz_screenWidth]));
    }];
    
    UIButton *topLabel = [[UIButton alloc]init];
    [bgView addSubview:topLabel];
//    [topLabel setTitle:@"我的积分: 60" forState:UIControlStateNormal];
//    topLabel.backgroundColor = [UIColor redColor];
//    topLabel.titleLabel.textAlignment = NSTextAlignmentLeft;
//    [topLabel setTitleColor:[UIColor cz_colorWithRed:105 green:105 blue:105] forState:UIControlStateNormal];
    [topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@58);
        make.right.top.mas_equalTo(bgView);
        make.left.mas_equalTo(bgView).offset(15);
    }];
    [topLabel addTarget:self action:@selector(topLabelClick) forControlEvents:UIControlEventTouchUpInside];
    
    UILabel *jifenLabel = [[UILabel alloc]init];
    self.jifenLabel = jifenLabel;
    [bgView addSubview:jifenLabel];
    jifenLabel.text = @"我的积分: 60";
    jifenLabel.backgroundColor = [UIColor whiteColor];
    jifenLabel.textAlignment = NSTextAlignmentLeft;
    jifenLabel.textColor = [UIColor cz_colorWithRed:105 green:105 blue:105];
    [jifenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(topLabel);
    }];
    NSMutableDictionary *pagramsD = @{@"token":[UserModel getUserModel].token}.mutableCopy;
    [WYHXNetWorkService netWorkSerViceRequestWithGetUrl:WKMeQueryQueryIntegralRecord withPostParams:pagramsD withBlock:^(NSDictionary *result, NSError *error) {
//        NSLog(@"result:%@",result);
        if ([result[@"code"] integerValue] == 200) {
            self.jifenString = [NSString stringWithFormat:@"%@",result[@"data"][@"allIntegralNum"]];
            jifenLabel.text = [NSString stringWithFormat:@"我的积分: %@",result[@"data"][@"allIntegralNum"]];
        }else{
            jifenLabel.text = [NSString stringWithFormat:@"我的积分: 0"];
        }
        
    }];
    
    UIView *downView = [[UIView alloc]init];
    [bgView addSubview:downView];
    downView.backgroundColor = [UIColor cz_colorWithRed:247 green:247 blue:247];
    [downView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@0);
        make.bottom.mas_equalTo(bgView.mas_bottom).offset(-4);
        make.height.equalTo(@10);
    }];
}
- (void)topLabelClick{
    if (_vkJiFenShopBlock) {
        self.vkJiFenShopBlock(_jifenString);
    }
}
@end
